#ifndef _EDGE_WATCHER_H_
#define _EDGE_WATCHER_H_

#include "../bitpointer/BitPointer.h"
#include "../bit/bit.h"
#include "../device/Device.h"
#include "../counter/Counter.h"

/*
	class : EdgeWatcher
	desc : This watches a bit and tells if the bit is high,
	low, rising, or falling.
*/
class EdgeWatcher : public Device
{
	private:
		//the bit being watched
		BitPointer bit;
		//the state of the edge watcher
		unsigned char state;
		//counter telling when I need to sample again
		Counter<unsigned char> sampleClock;

	public:
	//masking second bit will make the rise, fall 
	//turn into high, low signals respectively to simplify things.
	enum EdgeWatcherStates { HighEdge=0x01, 
				 LowEdge=0x00, 			
				 RisingEdge=0x03, 
				 FallingEdge=0x02};
		//default constructor.
		EdgeWatcher();
		//constructor set the bit pointer and the sample rate
		EdgeWatcher(BitPointer b, unsigned char rate);
		//samples the signal and sets the state
		void sampleSignal();
		//runs the edge watcher and samples the signal
		//when the counter flags it is time
		virtual void run();
		//returns if the signal is rising
		bool rising();
		//returns if the signal is falling
		bool falling();
		//returns if the signal is high
		bool high();
		//returns if the signal is low.
		bool low();
};
	
#endif


